package datasource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.activation.DataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017/9/14.
 */
public class C3P0Utils {
    private  static ComboPooledDataSource cpds=null;
        static {
             cpds=new ComboPooledDataSource();
             try{
                 cpds.setDriverClass("com.mysql.jdbc.Driver");
                 cpds.setJdbcUrl("jdbc:mysql://localhost:3307/jdbc");
                 cpds.setUser("root");
                 cpds.setPassword("123456");
                 cpds.setInitialPoolSize(5);
                 cpds.setMaxPoolSize(15);
             }catch (PropertyVetoException e){
                 e.printStackTrace();
             }
        }
        public  static  ComboPooledDataSource getDataSoi(){
            return cpds;
        }
        public  static Connection getConnection() throws SQLException{
            return  cpds.getConnection();
        }

}
